package com.example.javaee.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.javaee.common.result;
import com.example.javaee.entity.ExploitTask;
import com.example.javaee.entity.LateralMovement;
import com.example.javaee.service.AttackTaskService;
import com.example.javaee.service.ExploitTaskService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/exploitTask")
public class ExploitTaskController {
    @Autowired
    private ExploitTaskService exploitTaskService;

    //新增漏洞利用
    @PostMapping("/add")
    public result<ExploitTask> add(HttpServletRequest request, @RequestBody ExploitTask exploitTask) {

        LambdaQueryWrapper<ExploitTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ExploitTask::getExploitName, exploitTask.getExploitName());
        ExploitTask ET = exploitTaskService.getOne(queryWrapper);
        if (exploitTaskService.getOne(queryWrapper) != null) {
            return result.error("已存在");
        }
        exploitTaskService.save(exploitTask);
        return result.success(null, "漏洞利用添加成功");
    }
    //漏洞利用列表

    @GetMapping("/getExploitTasks/{pg}")
    public result<Page> page(@PathVariable Integer pg){
        //分页构造器
        Page<ExploitTask> pageInfo = new Page<>(pg,12);
        //条件构造器
        LambdaQueryWrapper<ExploitTask> queryWrapper = new LambdaQueryWrapper<>();
        //分页查询
        exploitTaskService.page(pageInfo,queryWrapper);
        System.out.printf(String.valueOf(pageInfo));
        return result.success(pageInfo,"查询成功");

    }

}
